home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9889 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: info.uah.edu!oreo!gbacon
  2. From: gbacon@oreo (Greg Bacon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: hex to dec function?
  5. Date: 14 Mar 1996 04:38:46 GMT
  6. Organization: The University of Alabama in Huntsville
  7. Message-ID: <4i87sm$7n0@info.uah.edu>
  8. References: <4gdh1b$bg@mailhost.mwmicro.com> <4hl8mk$1er@info.uah.edu> <313EE885.4511@cmt.lpr.mail.carel.fi>
  9. Reply-To: gbacon@CS.UAH.Edu
  10. NNTP-Posting-Host: oreo.aspire.cs.uah.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Ari Lukumies (aril@cmt.lpr.mail.carel.fi) wrote:
  14. : Greg Bacon wrote:
  15. : > 
  16.  
  17. : [snip]
  18.  
  19. : > Assuming you have a string representing some hexadecimal quantity and
  20. : > you want to print its equivalent decimal value:
  21. : > 
  22. : > #include <stdio.h>
  23. : > #include <stdlib.h>
  24. : > 
  25. : > /*
  26. : >  :
  27. : >  :
  28. : >  */
  29. : > {
  30. : >    char *strHexVal = "20";  /* 32 auf decimal */
  31. : > 
  32. : >    (void) printf("%d\n", strtol(strHexVal, (char **) NULL, 10));
  33. : > [snip]
  34.  
  35. : Just a quick sidenote: if you use strtol() in a printf call, use the
  36. : correct format string, also: "%ld\n".
  37.  
  38. : Later,
  39. :  AriL
  40.  
  41. OK, OK.. you got me.  I should have commented that I was assuming int
  42. and long were of the same length (a trait not often found on the
  43. braindead iAPX platform :).
  44.  
  45. The above works on most modern Unices.
  46.  
  47. Greg
  48. --
  49. Greg Bacon <gbacon@cs.uah.edu>
  50. University of Alabama in Huntsville
  51. CS Department Systems Support Team
  52.